﻿using Appliaction.Dto.Pinv;
using Appliaction.IAppServices.Pinv;
using AutoMapper;
using Domain.Entitys.Pinv;
using Domain.IRepositorys.Pinv;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Appliaction.AppServices.Pinv
{
    public class PuService : IPuService
    {
        private readonly IMapper mapper;
        private readonly IPuRepository puRepository;


        public PuService(IMapper mapper,IPuRepository puRepository)
        {
            this.mapper = mapper;
            this.puRepository = puRepository;
        }
        /// <summary>
        /// 分页添加查询信息
        /// </summary>
        /// <param name="Vendor_name"></param>
        /// <param name="Purret_code"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public List<Pu_details_Order> GetPuFyWhereSelect(string Vendor_name, string Purret_code, int currentPage, int pageSize)
        {
            return puRepository.GetPuFyWhereSelect(Vendor_name, Purret_code, currentPage, pageSize);
        }
        /// <summary>
        /// 添加查询总条数
        /// </summary>
        /// <param name="Vendor_name"></param>
        /// <param name="Purret_code"></param>
        /// <returns></returns>
        public int GetPuWhereCount(string Vendor_name, string Purret_code)
        {
            return puRepository.GetPuWhereCount(Vendor_name, Purret_code);
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="Pu_Order_Details_AddDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> PostPuAdd(Pu_Order_Details_AddDto<Pu_AddDto> Pu_Order_Details_AddDto)
        {
            Pinv_purret pu = mapper.Map<Pinv_purret>(Pu_Order_Details_AddDto.Pinv_Pu_Order_Dto);
            List<Pinv_podet> pinv_Podets = mapper.Map<List<Pinv_podet>>(Pu_Order_Details_AddDto.pu_Details_Add_Dtos);
            return puRepository.PostPuAdd(pu, pinv_Podets);
        }

        public Task<int> PutPuAudit(Pu_Order_details_Dto<Pu_Audit_Dto> pu_Order_Details_Dto)
        {
            Pinv_purret pu = mapper.Map<Pinv_purret>(pu_Order_Details_Dto.Pu_Order_Dto);
            List<Pinv_podet> pinv_Podets = mapper.Map<List<Pinv_podet>>(pu_Order_Details_Dto.pu_Details_Audit_Dtos);
            return puRepository.PutPuAudit(pu, pinv_Podets);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="pinv_Purret"></param>
        /// <returns></returns>
        public Task<int> PutPuDelete(Pu_deleteDto pinv_Purret)
        {
            Pinv_purret pu = mapper.Map<Pinv_purret>(pinv_Purret);
            return puRepository.PutPuDelete(pu);
        }

        public Task<int> PutPuUpdate(Pu_Order_Details_UpdateDto<Pu_UpdateDto> pu_Order_Details_UpdateDto)
        {
            Pinv_purret pu = mapper.Map<Pinv_purret>(pu_Order_Details_UpdateDto.Pinv_Pu_Order_Dto);
            List<Pinv_podet> pinv_Podets = mapper.Map<List<Pinv_podet>>(pu_Order_Details_UpdateDto.Pu_details_Update_Dto);
            return puRepository.PutPuUpdate(pu, pinv_Podets);
        }
    }
}
